package com.imooc.util;

import com.google.code.kaptcha.Constants;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Create By Liuqz
 * @date 2018/12/20 15:31
 */
public class CodeUtil {

    /**
     * 校验输入验证码是否与生成的一致
     * @param request
     * @return
     */
    public static boolean checkVerityCode(HttpServletRequest request) {
        //获取网页中实际的验证码值
        String verifyCodeExecpted = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        String verifyCodeActul = HttpServletRequestUtil.getString(request, "verifyCodeActual");
        if (verifyCodeActul != null || verifyCodeActul.equals(verifyCodeExecpted)) {
            return false;
        } else {
            return true;
        }
    }
}
